package com.qlylkj.lbk.model.repository

import com.qlylkj.lbk.model.api.BaseRepository
import com.qlylkj.lbk.model.api.NewsApi
import com.qlylkj.lbk.model.api.ResultResponse
import com.qlylkj.lbk.model.api.RetrofitHelper
import com.qlylkj.lbk.model.bean.NewsList

class NewsRepository: BaseRepository() {

    private val newsApi by lazy { RetrofitHelper.getService(NewsApi::class.java) }

    private fun requestBodyGetNewsList(offset: Int,pageSize: Int): MutableMap<String, Any> {
        val map = mutableMapOf<String, Any>()
        map["pageSize"] = pageSize
        map["pageNo"] = offset
        return map
    }

    suspend fun getNewsList(offset: Int,pageSize: Int = 10): ResultResponse<NewsList> {
        return safeApiCallEntity(
            call = { requestGetNewsList(offset, pageSize) },
            errorMessage = "获取链改新闻数据错误"
        )
    }

    private suspend fun requestGetNewsList(offset: Int,pageSize: Int): ResultResponse<NewsList> {
        val response = newsApi.getNewsList(requestBodyGetNewsList(offset, pageSize))
        return executeEntityResponse(response, {

        })
    }

}